package com.cj.logc.simple

import android.app.Application
import android.os.Environment
import com.bnq.logc.Logc
import com.bnq.logc.config.LogcConfig
import com.bnq.logc.utils.DeviceUtil
import java.io.File
import java.util.concurrent.TimeUnit

class App : Application() {

    override fun onCreate() {
        super.onCreate()
        Logc.init(LogcConfig.build {
            context = this@App
            isPrintLog = true
            isUploadLog = true
            customHost = BuildConfig.customHost
            bucketName = BuildConfig.bucketName
            uploadPublicKey = BuildConfig.uploadPublicKey
            uploadPrivateKey = BuildConfig.uploadPrivateKey
            uniqueDeviceId = ""
            isSendLog = true
            sendUrl = BuildConfig.sendUrl
            defaultSendBodyParamFun = {
                mutableMapOf(
                    "deviceId" to "123456",
                    "appVersion" to "1.0.0",
                    "shopCode" to "1004",
                    "posNumber" to "86",
                    "deviceType" to "1",
                    "cashierJobNo" to "112233",
                )
            }
            //storageDays = 30
            //lowMemoryByte = 1024 * 1024 * 200
            isDebug = true
            isOpenSimpleCacheLogUpload = true
            uploadScheduleConfig = LogcConfig.UploadScheduleConfig(2,TimeUnit.HOURS,LogcConfig.UploadScheduleConfig.UploadStrategy.ThreadScheduled)
            tmpScheduleUploadFileConfig = listOf(
                LogcConfig.TmpScheduleUploadFileConfig(
                    "gmc",
                    listOf(
                        File(Environment.getExternalStorageDirectory(),"umsips/umsgmc.log")),
                    listOf("logc/tmp/bank/union/gmc/${DeviceUtil.getUniqueId(this@App)}/umsips/umsgmc.log"),
                    2,
                    TimeUnit.HOURS,
                    true,
                    {callback:(Boolean)->Unit->
                        callback.invoke(true)
                    },
                    true
                )
            )
            fileUploadServer = LogcConfig.FileUploadServer.COS
            cosSecretId = BuildConfig.cosSecretId
            cosSecretKey = BuildConfig.cosSecretKey
            cosBucket = BuildConfig.cosBucket
            cosRegion = BuildConfig.cosRegion
            logWriteModeConfig = LogcConfig.LogWriteModeConfig(
                LogcConfig.LogWriteModeConfig.Mode.MMAP,
                encryptMode = LogcConfig.LogWriteModeConfig.EncryptMode.Fixed,
                serverPublicKey = "B51F6A593C97C77A183A3A8AF3D60CEEAEE045ECF9D53FDBBB394B37263491CAC0D47141D196702C340CDFD3CB498B35ECDDCA9F8351876F74DA138CDBFAB02C",
                serverPrivateKey = "0D1342B273E876D345232EF1194E0A2E5F83F0724563FCF88DF3E4B64A8DD7C4",
                mmapSafe = true
            )
        })
    }

}